<template>
    <view class="container">
        <view class="item" v-for="(item, index) in articleList" :key="index">
            <view class="title" v-if="item.likeTime">{{ item.likeTime }}</view>
            <PostCard :item="item"></PostCard>
        </view>
    </view>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import PostCard from '@/components/PostCard.vue';
import { onLoad } from '@dcloudio/uni-app';
import { useUserStore } from '@/store';
import type { ArticleItem } from '@/type/article';
import { API_getLikeRecordOrHistory } from '@/service/article';
const userStore = useUserStore();
const articleList = ref<ArticleItem[]>([]);
const getLikeRecord = async () => {
    let res = await API_getLikeRecordOrHistory(userStore.userInfo!.id!, 0);
    articleList.value = res.data;

    //提取日期部分
    articleList.value.map((item) => {
        item.likeTime = item.likeTime!.slice(0, 10);
    })
    let newDate = articleList.value[0].likeTime;
    for (let i = 1; i < articleList.value.length; i++) {
        if (articleList.value[i].likeTime === newDate) {
            articleList.value[i].likeTime = null;
        } else {
            newDate = articleList.value[i].likeTime;
        }
    }
}
onLoad(() => {
    getLikeRecord();
})
</script>
<style scoped lang="scss">
.container {

    padding: 20rpx;

    .title {
        font-size: 30rpx;
        color: #333;
        margin: 20rpx;
    }
}
</style>
